package com.du.linandroid.biz;

import android.content.Context;
import android.widget.Toast;

import com.du.linandroid.callback.CallBack;
import com.du.linandroid.util.Constant;
import com.du.linandroid.util.Util;
import com.tencent.mm.opensdk.modelmsg.SendAuth;

/**
 * Created by DuZiLin on 2018/3/29.
 */

public class WechatService implements IService {
    private Context mContext;
    public static CallBack mLoginCallBack;
    public WechatService(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void login(CallBack loginCallBack) {
        if(loginCallBack != null){
            mLoginCallBack = loginCallBack;
        }
        //登录开始
        mLoginCallBack.start();
        if(!ApiHolder.mWxApi.isWXAppInstalled()){
            Toast.makeText(mContext , "未安装微信客户端" , Toast.LENGTH_SHORT).show();
            mLoginCallBack.fail(Util.getFailJson(Constant.NO_INSTALLED_WECHAT_APP_CODE , Constant.NO_INSTALLED_WECHAT_APP_STR));
            mLoginCallBack.complete();
            return;
        }

        final SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "wechat_sdk";
        ApiHolder.mWxApi.sendReq(req);
    }
}
